package com.dianping.cat.configuration.server.transform;

import com.dianping.cat.configuration.server.IVisitor;
import com.dianping.cat.configuration.server.entity.ConsumerConfig;
import com.dianping.cat.configuration.server.entity.Domain;
import com.dianping.cat.configuration.server.entity.HarfsConfig;
import com.dianping.cat.configuration.server.entity.HdfsConfig;
import com.dianping.cat.configuration.server.entity.LongConfig;
import com.dianping.cat.configuration.server.entity.Property;
import com.dianping.cat.configuration.server.entity.Server;
import com.dianping.cat.configuration.server.entity.ServerConfig;
import com.dianping.cat.configuration.server.entity.StorageConfig;
import java.util.Stack;














public class DefaultValidator
  implements IVisitor
{
  private Path m_path = new Path();
  
  protected void assertRequired(String name, Object value) {
/*  34 */     if (value == null) {
/*  35 */       throw new RuntimeException(String.format("%s at path(%s) is required!", new Object[] { name, this.m_path }));
    }
  }

  
  public void visitConsumer(ConsumerConfig consumer) {
/*  41 */     this.m_path.down("consumer");

/*  43 */     visitConsumerChildren(consumer);

/*  45 */     this.m_path.up("consumer");
  }
  
  protected void visitConsumerChildren(ConsumerConfig consumer) {
/*  49 */     if (consumer.getLongConfig() != null) {
/*  50 */       visitLongConfig(consumer.getLongConfig());
    }
  }

  
  public void visitDomain(Domain domain) {
/*  56 */     this.m_path.down("domain");

/*  58 */     assertRequired("name", domain.getName());

/*  60 */     this.m_path.up("domain");
  }

  
  public void visitHarfs(HarfsConfig harfs) {
/*  65 */     this.m_path.down("harfs");

/*  67 */     assertRequired("id", harfs.getId());

/*  69 */     this.m_path.up("harfs");
  }

  
  public void visitHdfs(HdfsConfig hdfs) {
/*  74 */     this.m_path.down("hdfs");

/*  76 */     assertRequired("id", hdfs.getId());
    
    this.m_path.up("hdfs");
  }

  
  public void visitLongConfig(LongConfig longConfig) {
/*  83 */     this.m_path.down("long-config");

/*  85 */     visitLongConfigChildren(longConfig);

/*  87 */     this.m_path.up("long-config");
  }
  
  protected void visitLongConfigChildren(LongConfig longConfig) {
/*  91 */     for (Domain domain : longConfig.getDomains().values()) {
/*  92 */       visitDomain(domain);
    }
  }

  
  public void visitProperty(Property property) {
/*  98 */     this.m_path.down("property");

/* 100 */     assertRequired("name", property.getName());

/* 102 */     this.m_path.up("property");
  }

  
  public void visitServer(Server server) {
/* 107 */     this.m_path.down("server");

/* 109 */     assertRequired("id", server.getId());

/* 111 */     visitServerChildren(server);

/* 113 */     this.m_path.up("server");
  }
  
  protected void visitServerChildren(Server server) {
/* 117 */     this.m_path.down("properties");

/* 119 */     for (Property property : server.getProperties().values()) {
/* 120 */       visitProperty(property);
    }
    
/* 123 */     this.m_path.up("properties");

/* 125 */     if (server.getStorage() != null) {
/* 126 */       visitStorage(server.getStorage());
    }
    
/* 129 */     if (server.getConsumer() != null) {
/* 130 */       visitConsumer(server.getConsumer());
    }
  }

  
  public void visitServerConfig(ServerConfig serverConfig) {
/* 136 */     this.m_path.down("server-config");

/* 138 */     visitServerConfigChildren(serverConfig);

/* 140 */     this.m_path.up("server-config");
  }
  
  protected void visitServerConfigChildren(ServerConfig serverConfig) {
/* 144 */     for (Server server : serverConfig.getServers().values()) {
/* 145 */       visitServer(server);
    }
  }

  
  public void visitStorage(StorageConfig storage) {
/* 151 */     this.m_path.down("storage");

/* 153 */     visitStorageChildren(storage);

/* 155 */     this.m_path.up("storage");
  }
  
  protected void visitStorageChildren(StorageConfig storage) {
/* 159 */     for (HdfsConfig hdfs : storage.getHdfses().values()) {
/* 160 */       visitHdfs(hdfs);
    }
    
/* 163 */     for (HarfsConfig harfs : storage.getHarfses().values()) {
/* 164 */       visitHarfs(harfs);
    }
    
/* 167 */     this.m_path.down("properties");

/* 169 */     for (Property property : storage.getProperties().values()) {
/* 170 */       visitProperty(property);
    }
    
/* 173 */     this.m_path.up("properties");
  }
  
  static class Path {
/* 177 */     private Stack<String> m_sections = new Stack();
    
    public Path down(String nextSection) {
/* 180 */       this.m_sections.push(nextSection);

/* 182 */       return this;
    }

    
    public String toString() {
/* 187 */       StringBuilder sb = new StringBuilder();

/* 189 */       for (String section : this.m_sections) {
/* 190 */         sb.append('/').append(section);
      }
      
/* 193 */       return sb.toString();
    }
    
    public Path up(String currentSection) {
/* 197 */       if (this.m_sections.isEmpty() || !((String)this.m_sections.peek()).equals(currentSection)) {
/* 198 */         throw new RuntimeException("INTERNAL ERROR: stack mismatched!");
      }
      
/* 201 */       this.m_sections.pop();
/* 202 */       return this;
    }
  }
}


/* Location:              /Users/hanfei/Documents/apache-tomcat-9.0.24/webapps/cat/WEB-INF/lib/cat-core-3.0.0.jar!/com/dianping/cat/configuration/server/transform/DefaultValidator.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.0.7
 */